package com.zzxy.spring5.aspect;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

@Component
@Aspect
public class MyAspectJ {
    @Pointcut("execution(* com.zzxy.spring5.service..*.*(..))")
    public void myPointCut(){

    }
    @Before("myPointCut()")
    public void myBefore(JoinPoint jp) {
//        System.out.println(jp.getSignature().getName());
        System.out.println("my before...");
    }
@After("myPointCut()")
    public void myAfter(JoinPoint jp) {
//        System.out.println(jp.getSignature().getName());
        System.out.println("my after...");

    }

@AfterReturning(value = "myPointCut()" ,returning = "ret")
    public void myAfterReturning(JoinPoint jp,Object ret) {
//        System.out.println(jp.getSignature().getName());
        System.out.println("my after returning..." + ret);

    }
@AfterThrowing(value = "myPointCut()" , throwing = "e")
    public void myThrowing(JoinPoint jp,Throwable e){
//        System.out.println(jp.getSignature().getName());
        System.out.println("my throwing..." + e.getMessage());

    }
    @Around("myPointCut()")
    public Object myAround(ProceedingJoinPoint pjp) throws Throwable{
        System.out.println("my around before...");
        Object obj = pjp.proceed();
        System.out.println("my around after...");
        return  obj;
    }
}
